package com.system.manager.modules.development.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.manager.common.entity.Result;
import com.system.manager.common.exception.SysException;
import com.system.manager.modules.development.entity.DeveContract;
import com.system.manager.modules.development.mapper.DeveContractMapper;
import com.system.manager.modules.development.service.IDeveContractService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yxp
 * @since 2021-11-17
 */
@Service
public class DeveContractServiceImpl extends ServiceImpl<DeveContractMapper, DeveContract> implements IDeveContractService {
    @Autowired  DeveContractMapper deveContractMapper;

    /**
     * TODO 合同备案
     * @param deveContract
     */

    @Override
    public void insertContract(DeveContract deveContract) {
        try{
            deveContractMapper.insert(deveContract);
        }catch (Exception e){
            throw new SysException();
        }
    }

    /**
     * TODO 删除合同
     * @param id
     */

    @Override
    public void deleteContract(Integer id) {
        try{
            deveContractMapper.deleteById(id);
        }catch (Exception e){
            throw new SysException();
        }
    }

    @Override
    public Result selectAllContract(Integer page, Integer size, Integer id) {
        IPage<DeveContract> iPage = new Page<>(page,size);
        QueryWrapper<DeveContract> queryWrapper = new QueryWrapper<>();
        if(id != null){
            queryWrapper.eq("id",id);
        }
        //分页查询
        page(iPage,queryWrapper);
        List<DeveContract> records = iPage.getRecords();
        int total = (int) iPage.getTotal();
        return  Result.ok(records,total);
    }


}

